{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [],
   "source": [
    "import re\n",
    "dd={\n",
    "    'mm':re.compile('Ben'),\n",
    "    'ss':'Hello,my name is Ben.Please visit my websit at http://www.forta.com/.'\n",
    "}\n",
    "def pt():\n",
    "    print(dd['ss'])\n",
    "\n",
    "def ff():\n",
    "    print( ' '.join( dd['mm'].findall(dd['ss'])))\n",
    "\n",
    "def m(str_m):\n",
    "    dd['mm']=re.compile(str_m)\n",
    "\n",
    "def f(str_m):\n",
    "    m(str_m)\n",
    "    ff()\n",
    "def t(str_t):\n",
    "    dd['ss']=str_t\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Ben']\n"
     ]
    }
   ],
   "source": [
    "f()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['my', 'my']\n"
     ]
    }
   ],
   "source": [
    "f('my')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello,my name is Ben.Please visit my websit at http://www.forta.com/.\n"
     ]
    }
   ],
   "source": [
    "pt()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['llo']\n",
      "['vis']\n",
      "['www.']\n",
      "['m', 'a', 'm', 'a', 'm', 'a', 'a', 'm']\n"
     ]
    }
   ],
   "source": [
    "# . 匹配任意单个字符\n",
    "f('l.o')\n",
    "f('v.s')\n",
    "# 使用 \\ 进行转义\n",
    "f('www\\.')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "m a m a m a a m\n",
      "H ,       B . P           : / / . . / .\n"
     ]
    }
   ],
   "source": [
    "# 使用 []表示范围\n",
    "f('[ma]')\n",
    "# -表示区间 ^取反\n",
    "f('[^a-z]')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello,my name is Ben.Please visit my websit at http://www.forta.com/.\n"
     ]
    }
   ],
   "source": [
    "pt()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
